package com.ruoyi.web.controller.cooperative;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.GoodsSkuWithGoodNameAndExpressNameVo;
import com.ruoyi.system.service.IGoodsSpuService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GoodsSku;
import com.ruoyi.system.service.IGoodsSkuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 具体商品的参数Controller
 * 
 * @author ruoyi
 * @date 2022-01-26
 */
@RestController
@RequestMapping("/system/sku")
public class GoodsSkuController extends BaseController
{
    @Autowired
    private IGoodsSkuService goodsSkuService;
    /**
     * 查询具体商品的参数列表  带上商品的名字和快递的名字
     * */
    @PreAuthorize("@ss.hasPermi('system:sku:list')")
    @GetMapping("/listWithGoodNameAndExpressName")
    public TableDataInfo listWithGoodNameAndExpressName(GoodsSkuWithGoodNameAndExpressNameVo goodsSkuWithGoodNameAndExpressNameVo)
    {
        startPage();
        List<GoodsSkuWithGoodNameAndExpressNameVo> list = goodsSkuService.selectGoodsSkuVoList(goodsSkuWithGoodNameAndExpressNameVo);
        return getDataTable(list);
    }

    /**
     * 查询具体商品的参数列表
     */
    @PreAuthorize("@ss.hasPermi('system:sku:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSku goodsSku)
    {
        startPage();
        List<GoodsSku> list = goodsSkuService.selectGoodsSkuList(goodsSku);
        return getDataTable(list);
    }

    /**
     * 导出具体商品的参数列表
     */
    @PreAuthorize("@ss.hasPermi('system:sku:export')")
    @Log(title = "具体商品的参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSku goodsSku)
    {
        List<GoodsSku> list = goodsSkuService.selectGoodsSkuList(goodsSku);
        ExcelUtil<GoodsSku> util = new ExcelUtil<GoodsSku>(GoodsSku.class);
        util.exportExcel(response, list, "具体商品的参数数据");
    }

    /**
     * 获取具体商品的参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sku:query')")
    @GetMapping(value = "/{goodSkuId}")
    public AjaxResult getInfo(@PathVariable("goodSkuId") Long goodSkuId)
    {
        return AjaxResult.success(goodsSkuService.selectGoodsSkuByGoodSkuId(goodSkuId));
    }

    /**
     * 新增具体商品的参数
     */
    @PreAuthorize("@ss.hasPermi('system:sku:add')")
    @Log(title = "具体商品的参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsSku goodsSku)
    {
        return toAjax(goodsSkuService.insertGoodsSku(goodsSku));
    }

    /**
     * 修改具体商品的参数
     */
    @PreAuthorize("@ss.hasPermi('system:sku:edit')")
    @Log(title = "具体商品的参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsSku goodsSku)
    {
        return toAjax(goodsSkuService.updateGoodsSku(goodsSku));
    }

    /**
     * 删除具体商品的参数
     */
    @PreAuthorize("@ss.hasPermi('system:sku:remove')")
    @Log(title = "具体商品的参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodSkuIds}")
    public AjaxResult remove(@PathVariable Long[] goodSkuIds)
    {
        return toAjax(goodsSkuService.deleteGoodsSkuByGoodSkuIds(goodSkuIds));
    }
}
